package com.ruoyi.business.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.UserCourseMapper;
import com.ruoyi.business.domain.UserCourse;
import com.ruoyi.business.service.IUserCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 课程用户映射Service业务层处理
 * 
 * @author 吴倩芸
 * @date 2023-03-04
 */
@Service
public class UserCourseServiceImpl extends ServiceImpl<UserCourseMapper, UserCourse> implements IUserCourseService
{
    @Autowired
    private UserCourseMapper userCourseMapper;

    /**
     * 查询课程用户映射
     * 
     * @param id 课程用户映射主键
     * @return 课程用户映射
     */
    @Override
    public UserCourse selectUserCourseById(Long id)
    {
        return userCourseMapper.selectUserCourseById(id);
    }

    /**
     * 查询课程用户映射列表
     * 
     * @param userCourse 课程用户映射
     * @return 课程用户映射
     */
    @Override
    public List<UserCourse> selectUserCourseList(UserCourse userCourse)
    {
        Long userId = SecurityUtils.getUserId();
        userCourse.setUserId(userId);
        return userCourseMapper.selectUserCourseList(userCourse);
    }

    /**
     * 新增课程用户映射
     * 
     * @param userCourse 课程用户映射
     * @return 结果
     */
    @Override
    public int insertUserCourse(UserCourse userCourse)
    {
        if (null == userCourse.getUserId()) {
            userCourse.setUserId(SecurityUtils.getUserId());
        }
        return userCourseMapper.insertUserCourse(userCourse);
    }

    /**
     * 修改课程用户映射
     * 
     * @param userCourse 课程用户映射
     * @return 结果
     */
    @Override
    public int updateUserCourse(UserCourse userCourse)
    {
        return userCourseMapper.updateUserCourse(userCourse);
    }

    /**
     * 批量删除课程用户映射
     * 
     * @param ids 需要删除的课程用户映射主键
     * @return 结果
     */
    @Override
    public int deleteUserCourseByIds(Long[] ids)
    {
        return userCourseMapper.deleteUserCourseByIds(ids);
    }

    /**
     * 删除课程用户映射信息
     * 
     * @param id 课程用户映射主键
     * @return 结果
     */
    @Override
    public int deleteUserCourseById(Long id)
    {
        return userCourseMapper.deleteUserCourseById(id);
    }

    @Override
    public Boolean queryIsSubScribe(String courseId, String userId) {
        UserCourse userCourse = userCourseMapper.queryIsSubScribe(courseId, userId);
        return null != userCourse;
    }
}
